package istar.onto;
import istar.IActor;
import istar.IElement;
import istar.impl.AbstractElement;
import istar.impl.AbstractElementLink;
//import istar.impl.AbstractKnowledge;
import istar.impl.Belief;
import istar.impl.ContributionLink;
import istar.impl.Dependency;
import istar.impl.Goal;
import istar.impl.MeansEndLink;
import istar.impl.Resource;
import istar.impl.Softgoal;
import istar.impl.Task;
import istar.impl.TaskDecompositionLink;
import jade.content.onto.BasicOntology;
import jade.content.onto.CFReflectiveIntrospector;
import jade.content.onto.Ontology;
import jade.content.onto.OntologyException;
import jade.content.schema.AgentActionSchema;
import jade.content.schema.ConceptSchema;
import jade.content.schema.ObjectSchema;
import jade.content.schema.PrimitiveSchema;

public class IstarOntology extends Ontology implements IstarVocabulary{

	// The name identifying this ontology
	public static final String ONTOLOGY_NAME = "Istar-Ontology";
	
	// The singleton instance of this ontology
	private static Ontology theInstance = new IstarOntology();
	
	// This is the method to access the singleton music shop ontology object
	public static Ontology getInstance(){
		return theInstance;
	}
	
	// Private constructor
	private IstarOntology(){
	// The istar ontology extends the basic ontology
		super(ONTOLOGY_NAME, BasicOntology.getInstance(), new CFReflectiveIntrospector());
		try {
			
			PrimitiveSchema stringSchema  = (PrimitiveSchema)getSchema(BasicOntology.STRING);
			PrimitiveSchema integerSchema = (PrimitiveSchema)getSchema(BasicOntology.INTEGER);
			PrimitiveSchema floatSchema = (PrimitiveSchema)getSchema(BasicOntology.FLOAT);
			PrimitiveSchema booleanSchema = (PrimitiveSchema)getSchema(BasicOntology.BOOLEAN);
			
			ConceptSchema aidSchema = (ConceptSchema)getSchema(BasicOntology.AID);
			
			// Concepts
			ConceptSchema iactorSchema = new ConceptSchema(IACTOR);
			ConceptSchema iElementSchema = new ConceptSchema(IELEMENT);
			ConceptSchema abstractElementSchema = new ConceptSchema(ABSTRACTELEMENT);
			ConceptSchema goalSchema = new ConceptSchema(GOAL);
			ConceptSchema resourceSchema = new ConceptSchema(RESOURCE);
			ConceptSchema softgoalSchema = new ConceptSchema(SOFTGOAL);
			ConceptSchema taskSchema = new ConceptSchema(TASK);
			ConceptSchema abstractElementLinkSchema = new ConceptSchema(ABSTRACTELEMENTLINK);
			ConceptSchema taskDecompositionSchema = new ConceptSchema(TASKDECOMPOSITIONLINK);
			ConceptSchema meanEndSchema = new ConceptSchema(MEANSENDLINK);
			ConceptSchema contributionSchema = new ConceptSchema(CONTRIBUTIONLINK);
			ConceptSchema dependenceSchema = new ConceptSchema(DEPENDENCY);
			//ConceptSchema geographicalContextSchema = new ConceptSchema(GEOGRAPHICALCONTEXT);
			//ConceptSchema knowledgeSchema = new ConceptSchema(KNOWLEDGE);
			ConceptSchema beliefSchema = new ConceptSchema(BELIEF);
			
			iactorSchema.add(IACTOR_ID, stringSchema); 
			iactorSchema.add(IACTOR_NAME, stringSchema);
			iactorSchema.add(IACTOR_DEPENDEEELEMENTS, iElementSchema, 0, ObjectSchema.UNLIMITED);
			iactorSchema.add(IACTOR_DEPENDERELEMENTS, iElementSchema, 0, ObjectSchema.UNLIMITED);
			iactorSchema.add(IACTOR_INBOUNDARYELEMENTS, iElementSchema, 0, ObjectSchema.UNLIMITED);
			
			iElementSchema.add(IELEMENT_ID, integerSchema); 
			iElementSchema.add(IELEMENT_NAME, stringSchema);
			iElementSchema.add(IELEMENT_TOPIC, stringSchema);
			iElementSchema.add(IELEMENT_OWNER, iactorSchema);
			iElementSchema.add(IELEMENT_DEPENDENCIES, dependenceSchema, 0, ObjectSchema.UNLIMITED);
			iElementSchema.add(IELEMENT_MEANSENDLINKS, meanEndSchema, 0, ObjectSchema.UNLIMITED);
			iElementSchema.add(IELEMENT_SUPPORTS, abstractElementSchema, 0, ObjectSchema.UNLIMITED);
			
			abstractElementSchema.addSuperSchema(iElementSchema);

			goalSchema.addSuperSchema(abstractElementSchema);
			goalSchema.add(GOAL_STATE, integerSchema);

			resourceSchema.addSuperSchema(abstractElementSchema);
			resourceSchema.add(RESOURCE_VALUE, floatSchema);
			resourceSchema.add(RESOURCE_QUANTITY, integerSchema);

			softgoalSchema.addSuperSchema(abstractElementSchema);
			softgoalSchema.add(SOFTGOAL_STATE, integerSchema);
			softgoalSchema.add(SOFTGOAL_CONTRIBUTESFOR, contributionSchema, 0, ObjectSchema.UNLIMITED);
			
			taskSchema.addSuperSchema(abstractElementSchema);
			taskSchema.add(TASK_COST, floatSchema);
			taskSchema.add(TASK_PROCESSED, booleanSchema);
			taskSchema.add(TASK_PARAMS, iElementSchema, 0, ObjectSchema.UNLIMITED);
			taskSchema.add(TASK_MYDECOMPOSITIONLINK, taskDecompositionSchema, 0, ObjectSchema.UNLIMITED);
			taskSchema.add(TASK_MEANSFOR, meanEndSchema, 0, ObjectSchema.UNLIMITED);

			//geographicalContextSchema.add(GEOGRAPHICALCONTEXT_NAME, stringSchema);
			//geographicalContextSchema.add(GEOGRAPHICALCONTEXT_TYPE, integerSchema);
			//geographicalContextSchema.add(GEOGRAPHICALCONTEXT_ADDRESS, stringSchema);
			
			//knowledgeSchema.addSuperSchema(abstractElementSchema);
			//knowledgeSchema.add(KNOWLEDGE_CONTEXT, geographicalContextSchema);
			//knowledgeSchema.add(KNOWLEDGE_TOPIC, iElementSchema);
			
			beliefSchema.addSuperSchema(abstractElementSchema);
			beliefSchema.add(BELIEF_TOPIC, iElementSchema);
			beliefSchema.add(BELIEF_PROBABILITY, floatSchema);
			
			abstractElementLinkSchema.add(ABSTRACTELEMENTLINK_TARGETELEMENT,iElementSchema); 
			abstractElementLinkSchema.add(ABSTRACTELEMENTLINK_NAME, stringSchema);
			abstractElementLinkSchema.add(ABSTRACTELEMENTLINK_OWNER, iElementSchema);

			meanEndSchema.addSuperSchema(abstractElementLinkSchema);
			
			taskDecompositionSchema.addSuperSchema(abstractElementLinkSchema);
			taskDecompositionSchema.add(TASKDECOMPOSITIONLINK_TYPE, integerSchema);
			
			contributionSchema.addSuperSchema(abstractElementLinkSchema);
			contributionSchema.add(CONTRIBUTIONLINK_VALUE, integerSchema);
			
			dependenceSchema.add(DEPENDENCY_NAME, stringSchema);
			dependenceSchema.add(DEPENDENCY_TYPE, integerSchema);
			dependenceSchema.add(DEPENDENCY_DEPENDUM, iElementSchema);
			dependenceSchema.add(DEPENDENCY_DEPENDER, iactorSchema);
			dependenceSchema.add(DEPENDENCY_DEPENDEE, iactorSchema);
			dependenceSchema.add(DEPENDENCY_DEPENDERELEMENT, iElementSchema);
			dependenceSchema.add(DEPENDENCY_DEPENDEEELEMENT, iElementSchema);
			
			add(iactorSchema, IActor.class);
			add(iElementSchema, IElement.class);
			add(goalSchema, Goal.class);
			add(abstractElementSchema, AbstractElement.class);
			add(resourceSchema, Resource.class);
			add(softgoalSchema, Softgoal.class);
			add(taskSchema, Task.class);
			//add(geographicalContextSchema, GeographicalContext.class);
			//add(knowledgeSchema, AbstractKnowledge.class);
			add(beliefSchema, Belief.class);
			add(abstractElementLinkSchema, AbstractElementLink.class);
			add(meanEndSchema, MeansEndLink.class);
			add(taskDecompositionSchema, TaskDecompositionLink.class);
			add(contributionSchema, ContributionLink.class);
			add(dependenceSchema, Dependency.class);

			// Actions
			AgentActionSchema accomplishSchema = new AgentActionSchema(ACCOMPLISH);
			accomplishSchema.add(ACCOMPLISH_ELEMENT, iElementSchema);
			accomplishSchema.add(ACCOMPLISH_AGENT, aidSchema);

			AgentActionSchema accomplishTaskSchema = new AgentActionSchema(ACCOMPLISH_TASK);
			accomplishTaskSchema.addSuperSchema(accomplishSchema);
			accomplishTaskSchema.add(ACCOMPLISH_PARAMS, iElementSchema, 0, ObjectSchema.UNLIMITED);
			
			add(accomplishSchema);
			add(accomplishTaskSchema);
			
		}
		catch (OntologyException oe) {
			oe.printStackTrace();
		}
	}
	
}
